﻿let url_ = this.baseUrl + "/{{ operation.Path }}{% if operation.HasQueryParameters %}?{% endif %}";
{% for parameter in operation.PathParameters -%}
{%     if parameter.IsRequired -%}
if ({{ parameter.VariableName }} === undefined || {{ parameter.VariableName }} === null)
    throw new Error("The parameter '{{ parameter.VariableName }}' must be defined.");
{%     else -%}
if ({{ parameter.VariableName }} !== null && {{ parameter.VariableName }} !== undefined)
{%     endif -%}
{%     if parameter.IsDateArray -%}
url_ = url_.replace("{{ "{" }}{{ parameter.Name }}}", encodeURIComponent({{ parameter.VariableName }}.map(s_ => s_ ? s_.toJSON() : "null").join())); 
{%     elseif parameter.IsDate -%}
url_ = url_.replace("{{ "{" }}{{ parameter.Name }}}", encodeURIComponent({{ parameter.VariableName }} ? "" + {{ parameter.VariableName }}.toJSON() : "null")); 
{%     elseif parameter.IsArray -%}
url_ = url_.replace("{{ "{" }}{{ parameter.Name }}}", encodeURIComponent({{ parameter.VariableName }}.join())); 
{%     else -%}
url_ = url_.replace("{{ "{" }}{{ parameter.Name }}}", encodeURIComponent("" + {{ parameter.VariableName }})); 
{%     endif -%}
{%     if parameter.IsOptional -%}
else
    url_ = url_.replace("/{{ "{" }}{{ parameter.Name }}}", "");
{%     endif -%}
{% endfor -%}
{% for parameter in operation.QueryParameters -%}
{%     if parameter.IsRequired -%}
{%         if parameter.IsNullable -%}
if ({{ parameter.VariableName }} === undefined)
    throw new Error("The parameter '{{ parameter.VariableName }}' must be defined.");
else
{%         else -%}
if ({{ parameter.VariableName }} === undefined || {{ parameter.VariableName }} === null)
    throw new Error("The parameter '{{ parameter.VariableName }}' must be defined and cannot be null.");
else
{%         endif -%}
{%     else -%}
{%         if parameter.IsNullable -%}
if ({{ parameter.VariableName }} !== undefined)
{%         else -%}
if ({{ parameter.VariableName }} === null)
    throw new Error("The parameter '{{ parameter.VariableName }}' cannot be null.");
else if ({{ parameter.VariableName }} !== undefined)
{%         endif -%}
{%     endif -%}
{%     if parameter.IsDateArray -%}
    {{ parameter.VariableName }} && {{ parameter.VariableName }}.forEach(item_ => { url_ += "{{ parameter.Name }}=" + encodeURIComponent(item_ ? "" + item_.toJSON() : "null") + "&"; });
{%     elseif parameter.IsObjectArray -%}
    {{ parameter.VariableName }} && {{ parameter.VariableName }}.forEach((item, index) => { 
        for (let attr in item)
			if (item.hasOwnProperty(attr)) {
				url_ += "{{ parameter.Name }}[" + index + "]." + attr + "=" + encodeURIComponent("" + (<any>item)[attr]) + "&";
			}
    });
{%     elseif parameter.IsDate -%}
    url_ += "{{ parameter.Name }}=" + encodeURIComponent({{ parameter.VariableName }} ? "" + {{ parameter.VariableName }}.toJSON() : "{{ QueryNullValue }}") + "&"; 
{%     elseif parameter.IsArray -%}
    {{ parameter.VariableName }} && {{ parameter.VariableName }}.forEach(item => { url_ += "{{ parameter.Name }}=" + encodeURIComponent("" + item) + "&"; });
{%     else -%}
    url_ += "{{ parameter.Name }}=" + encodeURIComponent("" + {{ parameter.VariableName }}) + "&"; 
{%     endif -%}
{% endfor -%}
url_ = url_.replace(/[?&]$/, "");
